package com.song.dubbo3service.service;

import com.song.dubbo3.api.Dubbo3TestService;
import com.song.dubbo3.api.MyException;
import com.song.dubbo3service.filter.ThreadLocalUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.apache.dubbo.rpc.RpcException;

/**
 * @Author SHI YUAN
 * @DATE 2022/2/7 11:51 PM
 * @Version 1.0
 * @Desc
 */
@Slf4j
@DubboService
public class Dubbo3ServiceImpl implements Dubbo3TestService {

    @Override
    public String sayHello(String name) throws MyException {
        String traceId = ThreadLocalUtil.getValue();
        log.info("[Dubbo3ServiceImpl] params:{}, traceId:{}, threadId:{}",
                name, traceId, Thread.currentThread().getId());

        switch (name){
            case "1":
                // 方法签名
                throw new MyException(-1, "error my exception");
            case "2":
                // jdk异常
                throw new IllegalArgumentException("IllegalArgumentException");
            case "3":
                // 自定义
                throw new CommonException("CommonException");
            case "4":
                throw new RpcException("RpcException");
            default:
                break;
        }
        return "service " + name;
    }
}
